package edu.hhu.controller;

import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.jfinal.core.Controller;
import com.jfinal.ext.render.excel.PoiRender;

import edu.hhu.dynamic.table.Conditions;
import edu.hhu.dynamic.table.TableService;
import tree.TreeService;

public class TableController extends Controller{
	public void showTable() {
		Conditions conditions=new Conditions();
		//wellcode节点
		String nodeStr=this.getPara("nodeStr");
		nodeStr=nodeStr.substring(0, nodeStr.length()-1);
		conditions.setNodeStr(nodeStr);
		//属性指标
		String fieldStr=this.getPara("fieldStr");
		fieldStr=fieldStr.substring(0, fieldStr.length()-1);
		conditions.setFieldStr(fieldStr);
		//开始日期 截至日期
		String s_date=this.getPara("s_date");
		conditions.setS_date(s_date);
		String e_date=this.getPara("e_date");
		conditions.setE_date(e_date);
		//分页信息
		String page=this.getPara("page");
		conditions.setPage(page);
		String limit=this.getPara("limit");
		conditions.setLimit(limit);
		String start=this.getPara("start");
		conditions.setStart(start);
		//真假表切换
		String tablename=this.getPara("tablename");
		conditions.setTablename(tablename);
		//tablename="pcdtsjtrue";
		//tablename="jzhz";
		//tablename="qkhz";
		//归一
		String level=this.getPara("level");
		conditions.setLevel(level);
		//判断数据来源的table
		if(level.equals("3")){
			conditions.setTablename("pcdtsjtrue");
		}else if(level.equals("2")){
			conditions.setTablename("jzhz");
		}else if(level.equals("1")){
			conditions.setTablename("qkhz");
		}else{
			conditions.setTablename("qthz");
		}
		String chartStyle=this.getPara("chartStyle");
		conditions.setChartStyle(chartStyle);
		String normalType=this.getPara("normalType");
		conditions.setNormalType(normalType);
		//输出查询条件
//		System.out.println(JSON.toJSONString(conditions));
		TableService tableservice=new TableService();
		//返回table数据
		String json="";
		//折线图
		//单井
		if(chartStyle.equals("line")&&level.equals("3")){
			 //单井不归一、时间归一
			if(normalType.equals("0")||normalType.equals("1")){
				json=tableservice.getData(conditions);
			}
            if(normalType.equals("2")||normalType.equals("3")){
				//单井产量归一、全归一
				json=tableservice.getData1(conditions);
			}
		}
		//井组、区块、气田
		if (chartStyle.equals("line") && !level.equals("3")) {
			// 井组、区块、气田不归一、时间归一
			if (normalType.equals("0") || normalType.equals("1")) {
				json = tableservice.getData2(conditions);
			}
			
		}
		

		renderJson(json);
	}
	
	

}
